package com.cai.controller;

import com.cai.mapper.UserMapper;
import com.cai.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class UserController {

    @Autowired
    private UserMapper userMapper;

    // 查询所有用户
    @GetMapping("/queryUserList")
    public List<User> queryUserList() {
        return userMapper.queryUserList();
    }

    // 通过id查询用户
    @GetMapping("/queryUserById/{id}")
    public User queryUserById(@PathVariable("id") int id) {
        return userMapper.queryUserById(id);
    }

    // 新增用户
    @PostMapping("/addUser/user")
    public int addUser(User user) {
        return userMapper.addUser(user);
    }

    // 修改用户
    @PutMapping("/updateUser/user")
    public int updateUser(User user) {
        return userMapper.updateUser(user);
    }

    // 删除用户
    @DeleteMapping("/deleteUser/{id}")
    public int deleteUser(@PathVariable("id") int id) {
        return userMapper.deleteUser(id);
    }
}
